Nmap field guide
Common commands for host discovery, port scanning, service enumeration, NSE scripting, performance tuning, and reporting.
TARGET, DOMAIN, and other placeholders before use.Host Discovery
Find live hosts before scanning ports. By default Nmap sends ARP locally and ICMP/TCP probes remotely.
nmap -sn 192.168.1.0/24Ping sweep: find all live hosts on the subnet without a port scan.
nmap -sn -PR 192.168.1.0/24ARP discovery only: fast on local networks and useful when host firewalls block other probes.
nmap -sn -PE -PP -PM TARGETICMP discovery using Echo, Timestamp, and Address Mask requests.
nmap -sn -PS22,80,443 -PA80,443 TARGETTCP SYN and ACK discovery on common ports when ICMP is blocked.
nmap -sn -PU53,161 TARGETUDP discovery on DNS and SNMP ports.
nmap -Pn TARGETSkip discovery and treat hosts as online when ping is blocked.
nmap -sL 10.0.0.0/24List scan: reverse DNS lookup only; no packets are sent to targets.
Scan Types
Choose a TCP or UDP technique for the service and permissions you are testing.
nmap -sS TARGETTCP SYN scan: fast and commonly recommended; requires raw socket privileges.
nmap -sU --top-ports 200 TARGETUDP scan on the top 200 ports; useful for SNMP, DNS, and TFTP services.
nmap -sS -sU -p T:1-1000,U:53,111,161,500 TARGETCombined TCP and UDP scan with separate port selections.
nmap -sI zombie_ip TARGETIdle scan using a permitted intermediary host; results do not originate directly from your IP.
Port Specification
Control exactly which ports Nmap scans. The default is the top 1,000 ports.
nmap -p- TARGETScan all 65,535 TCP ports.
nmap -p 80,443,8080,8443 TARGETScan specific web ports only.
nmap -p 1-1024 TARGETScan a port range, such as all privileged ports.
nmap --top-ports 100 TARGETScan only the 100 most common ports for fast recon.
nmap -p- --min-rate=1000 TARGETFull TCP port scan with a minimum packet rate.
nmap -p T:80,443,U:53,161 TARGETMix TCP and UDP ports in one command.
Service & Version Detection
Identify what is running on open ports and which versions are exposed.
nmap -sV TARGETProbe open ports to determine service and version.
nmap -sV --version-intensity 9 TARGETMaximum version detection using all available probes.
nmap -sV --version-light TARGETLight version scan at intensity 2 for faster results.
nmap -sC TARGETRun the default NSE scripts; equivalent to --script=default.
nmap -sC -sV -p 22,80,443 TARGETClassic combination: version detection and default scripts on selected ports.
nmap -A TARGETAggressive scan: version detection, default scripts, OS detection, and traceroute.
OS Detection
Fingerprint the operating system by analyzing TCP/IP stack behavior.
nmap -O TARGETOS detection; accuracy improves with at least one open and one closed port.
nmap -O --osscan-guess TARGETPrint the best OS guess even when the fingerprint is uncertain.
nmap -O --osscan-limit TARGETAttempt OS detection only on hosts with suitable open and closed ports.
NSE Scripts
Use the Nmap Scripting Engine for vulnerability checks, enumeration, and service testing.
Tip: List available scripts with ls /usr/share/nmap/scripts/ | wc -l.
Script Categories
nmap --script=default TARGETRun default scripts; safe and informative for many assessments.
nmap --script=vuln TARGETRun vulnerability detection scripts to identify CVEs and misconfigurations.
nmap --script=safe TARGETRun scripts marked safe.
nmap --script="vuln and safe" TARGETRun scripts that are both in the vulnerability and safe categories.
Most Useful Scripts
nmap -p 445 --script=smb-enum-shares,smb-enum-users,smb-os-discovery TARGETSMB enumeration: shares, users, and OS information.
nmap -p 80,443 --script=http-enum,http-headers,http-methods,http-title TARGETHTTP enumeration: directories, headers, methods, and page titles.
nmap -p 53 --script=dns-zone-transfer --script-args dns-zone-transfer.domain=DOMAIN TARGETAttempt a DNS zone transfer against an authorized domain.
nmap -p 21 --script=ftp-anon,ftp-bounce,ftp-syst TARGETFTP enumeration: anonymous access, bounce behavior, and system information.
nmap -p 25 --script=smtp-enum-users,smtp-open-relay TARGETCheck SMTP user enumeration and open-relay behavior.
nmap -p 3306 --script=mysql-enum,mysql-info,mysql-empty-password TARGETMySQL information, user enumeration, and empty-password checks.
nmap -p 443 --script=ssl-enum-ciphers,ssl-cert,ssl-heartbleed TARGETSSL/TLS audit: ciphers, certificate information, and Heartbleed checks.
nmap --script=smb-vuln-ms17-010 -p 445 TARGETCheck for the MS17-010 vulnerability on an authorized SMB host.
Script Arguments
nmap --script=http-brute --script-args http-brute.path=/admin,userdb=users.txt,passdb=pass.txt -p 80 TARGETTest an authorized HTTP login with custom wordlists and a target path.
nmap --script=http-put --script-args http-put.url=/uploads/shell.php,http-put.file=shell.php -p 80 TARGETTest whether an authorized server permits HTTP PUT uploads.
Firewall & IDS Evasion
These options alter scan traffic and can trigger defenses. Use them only in an approved assessment.
nmap -f TARGETFragment packets into small pieces.
nmap --mtu 16 TARGETSet a custom MTU; the value must be a multiple of 8.
nmap -D RND:10 TARGETGenerate 10 random decoy addresses.
nmap -D decoy1,decoy2,decoy3,ME TARGETUse specific decoys; ME marks your position.
nmap -S SPOOFED_IP -e eth0 -Pn TARGETSpoof the source IP; results will not return to your host.
nmap -g 53 TARGETUse source port 53 for testing source-port filtering.
nmap --data-length 25 TARGETAppend random data to packets.
nmap --scan-delay 5s TARGETWait five seconds between probes.
nmap --badsum TARGETSend packets with invalid checksums to test intermediary behavior.
Timing & Performance
T0-T1 prioritize stealth, T3 is the default, and T4-T5 prioritize speed.
nmap -T4 --min-rate=1000 -p- TARGETFast full scan with aggressive timing and a minimum packet rate.
nmap --min-parallelism 100 TARGETKeep at least 100 probes in parallel.
nmap --max-retries 1 TARGETLimit retransmissions to one for faster, less reliable scans.
nmap --host-timeout 30s TARGETSkip hosts that take more than 30 seconds.
Output Formats
Save results for review and later processing. Use -oA when you want all three primary formats.
nmap -oN scan.txt TARGETNormal, human-readable output.
nmap -oX scan.xml TARGETXML output for parsers and security tools.
nmap -oG scan.gnmap TARGETGrepable output for shell pipelines.
nmap -oA scan TARGETWrite normal, XML, and grepable output together.
nmap -oG - TARGET | grep "open" | awk '{print $2}'Extract IP addresses with open ports from grepable output.
nmap -v --reason TARGETShow verbose output and why each port is open, closed, or filtered.
Real-World Combos
Copy-paste workflows for common authorized pentesting scenarios.
nmap -p- --min-rate=1000 -T4 TARGET -oN allports.txtInitial recon: fast full port discovery.
nmap -p OPEN_PORTS -sC -sV -oA detailed TARGETDeep scan discovered ports with scripts and version detection.
nmap -p 80,443,8080,8443 -sV --script="http-*" TARGETFull HTTP enumeration on common web ports.
nmap -p 53,88,135,139,389,445,464,636,3268,3269 -sV -sC TARGETDomain controller scan covering DNS, Kerberos, RPC, SMB, LDAP, and Global Catalog.
nmap -sV --script=vuln -p OPEN_PORTS TARGET -oA vulnscanRun vulnerability scripts on discovered open ports.
nmap -sS -T1 -f -D RND:5 -g 53 --data-length 25 TARGETSlow SYN scan with fragmentation, decoys, source-port testing, and padding.
nmap -sn 10.0.0.0/24 -oG - | grep "Up" | awk '{print $2}' > live_hosts.txtDiscover live hosts and save them for a later scan.
nmap -iL live_hosts.txt -p- --min-rate=1000 -oA full_scanRun a full port scan against hosts read from a file.
No matching commands found.